{% extends 'base.html' %} {% block css%}
<style type="text/css">

</style>
{% endblock %} {% block body%}
<div class="row">
    <div class="col-md-4">

	  	<h3>设备</h3>
			<table class="table table-hover table-condensed form-inline">
				<tr>
					<td>串口号</td>
					<td>
						<select class="form-control" id="port_val" style="width:140px; height:30px">
						</select>
					</td>
				</tr>
				<tr class="hide">
					<td>波特率</td>
					<td><input type="text" style="width:140px; height:30px" id="baudrate_val"></td>
				</tr>
				<tr>
					<td colspan="2">
						<button class="btn btn-primary" id="btn_set_device_settings">
						确定
						</button>
					</td>
				</tr>
			</table>

			<h3>系统设置</h3>
			<table class="table table-hover table-condensed">
				<tr>
					<td>系统时间</td>
					<td>
						<div class="form-group">
							<div class="input-group date form_datetime" data-date="" data-date-format="yyyy-mm-dd hh:ii" data-link-field="dtp_input1">
								<input id="datetime_val" class="form-control" type="text" value="" readonly>
								<span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
								<span class="input-group-addon"><span class="glyphicon glyphicon-th"></span></span>
							</div>
							<input type="hidden" id="dtp_input1" value="" />
						</div>
					</td>
				</tr>

				<tr>
					<td colspan="2">
						<button class="btn btn-primary" id="btn_set_sys_datetime">
						设置
						</button>
					</td>
				</tr>
			</table>

			<h3>软件升级</h3>
			<table class="table table-hover table-condensed">

				<tr>
					<td>
						<button class="btn btn-success" id="btn_set_software_update">
						升级到最新版本
						</button>
					</td>

					<td>
						<button class="btn btn-success" id="btn_set_software_reboot">
						重启软件
						</button>
					</td>
				</tr>
			</table>			
    </div>
    <div class="col-md-4">
    </div>
    <div class="col-md-4">
    	<!-- <a href="/m/demo">new demo!</a> -->
    </div>
</div>

{% endblock %} {% block js%}
{{ super() }}
<script type="text/javascript">

function btn_get_device_settings()
{
    $.post(
                "api/get_device_settings", {

                },
                function(data, status) {
                    console.log(data)
                    d = JSON.parse(data)
                    console.log(d)
                    $("#port_val").html(d.port);
                    // toastr["success"]("数据已设置.");
                }
            );
}


$(document).ready(function() {

    btn_get_device_settings();

    $('.form_datetime').datetimepicker({
        language:  'zh-CN',
        format: 'yyyy-mm-dd hh:ii',
        weekStart: 1,
        todayBtn:  1,
		autoclose: 1,
		todayHighlight: 1,
		startView: 2,
		forceParse: 0,
        showMeridian: 1
    });
		
    $("#btn_set_sys_datetime").click(function(){
		var datetime_val = $("#datetime_val").val();
		console.log(datetime_val);
		$.post(
                "api/set_sys_datetime", {
                    datetime_val: datetime_val,
                },
                function(data, status) {
                    console.log(data)            
                    toastr["success"]("数据已设置.");
                }
            );

	});


    $("#btn_set_device_settings").click(function(){
		device_port_val = $("#port_val").val();
		$.post(
		"api/set_device_settings", {
			device_port_val: device_port_val,
		},
		function(data, status) {
			console.log(data)            
			toastr["success"]("数据已设置.");
		}
	);
	});


    $("#btn_set_software_update").click(function(){

		$.post(
		"api/set_software_update", {

		},
		function(data, status) {
			console.log(data)            
			toastr["success"]("恭喜你，软件已升级到最新. 请重启软件并刷新");
		}
	);
	});


    $("#btn_set_software_reboot").click(function(){

		$.post(
		"api/set_software_reboot", {

		},
		function(data, status) {
			// console.log(data);
		}
	);
	});



	

});

</script>
{% endblock %}